/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.minierp.bean.UserBean;
import com.minierp.dao.PhoneBookDao;
import com.minierp.helper.EncCommonHelper;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class PhoneBookMACtr extends MultiActionController {
	private PhoneBookDao phoneBookDao;
	private String listView;

	public ModelAndView handleList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listView);
		String searchKey = request.getParameter("search_key");
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		int perPageNum = EncCommonHelper.getPageSize(request);
		int total = this.phoneBookDao.getListCount(ub.getUser().getStafferId(),
				searchKey);
		int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
				perPageNum);
		int startIndex = (pageno - 1) * perPageNum;
		List list = this.phoneBookDao.getList(ub.getUser().getStafferId(),
				searchKey, startIndex, perPageNum);
		mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
				perPageNum, pageno));
		mv.addObject("searchKey", searchKey);
		return mv;
	}

	public ModelAndView handleDelete(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String retUrl = request.getParameter("from_url");
		ModelAndView mv = new ModelAndView("redirect:" + retUrl);
		this.phoneBookDao.delete(Long.parseLong(request.getParameter("id")));
		EncCommonHelper.setAlertMessage(request, "删除成功！");
		return mv;
	}

	public String getListView() {
		return this.listView;
	}

	public void setListView(String listView) {
		this.listView = listView;
	}

	public PhoneBookDao getPhoneBookDao() {
		return this.phoneBookDao;
	}

	public void setPhoneBookDao(PhoneBookDao phoneBookDao) {
		this.phoneBookDao = phoneBookDao;
	}
}